package utils;

import beans.FullJobState;
import beans.HttpResultList;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.math3.analysis.function.Power;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class PowerUtil {

    private static String power;

    static{
        try{
            String url = Thread.currentThread().getContextClassLoader().getResource("power.json").getPath();
            BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(url)));
            String tempPowerString = null;
            StringBuilder powerS = new StringBuilder();
            while ((tempPowerString = bufferedReader.readLine()) != null) {
                powerS.append(tempPowerString);
            }
            power = powerS.toString();    //json转换字符串
            bufferedReader.close();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    //public String getPower(){ return power; }

    public static ArrayList<String> pickPower(String user_code){
        JSONObject result = JSONObject.fromObject(power);
        JSONObject code = result.getJSONObject(user_code);
        ArrayList<String> powerList = new ArrayList();
        String dataStr = null;
        dataStr = code.getString("permissionUri");
        String s1=dataStr.replace("[","");
        String s2=s1.replace("]","");
        String s3=s2.replace("\"","");
        String[] data= s3.split(",");
        for(int i=0;i<data.length;i++) {
            powerList.add(data[i]);
        }
        return powerList;
    }



}
